//
//  CatDevicesViewController.m
//  DoorBell
//
//  Created by Chun Hung Cheung on 2023/3/14.
//  Copyright © 2023 Chun Hung Cheung. All rights reserved.
//

#import "CatDevicesViewController.h"
#import "CatBluViewController.h"
@interface CatDevicesViewController ()
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *secondLabel;
@property(nonatomic,strong)UIImageView *devicesImage;
@property(nonatomic,strong)UIButton *selectedButton;
@property(nonatomic,strong)UIButton *nextButton;
@end

@implementation CatDevicesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.view.backgroundColor = [UIColor whiteColor];
    [self setup];
     self.titleLabel.text = NSLocalizedString(@"重置设备", nil);
     self.secondLabel.text = NSLocalizedString(@"接通电源后,确认指示灯在快闪或听到提示音", nil);
     self.devicesImage.image = [UIImage imageNamed:@"cat_img_reset"];
    [self.selectedButton setTitleColor:[HexChangeRGB colorWithHexString:@"#333333"] forState:UIControlStateNormal];
    [self.nextButton setTitle:NSLocalizedString(@"下一步", nil) forState:UIControlStateNormal];

    

  
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
    [self.navigationController.navigationBar setBackgroundImage:[Tooles imageWithColor:WXHColor(255, 255, 255, 1.0)] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
     self.navigationController.navigationBar.shadowImage = [Tooles imageWithColor:[HexChangeRGB colorWithHexString:@"#EBEBEB"]];
    [UIApplication sharedApplication].statusBarStyle =  UIStatusBarStyleDefault;
   
   if(@available(iOS 15.0,*)){
     UINavigationBarAppearance *apperance=[[UINavigationBarAppearance alloc]init];
     apperance.backgroundColor = [UIColor whiteColor];//设置背景色
     self.navigationController.navigationBar.standardAppearance = apperance;
     self.navigationController.navigationBar.scrollEdgeAppearance = apperance;
   }
    
}

- (void)setup
{
     self.title = NSLocalizedString(@"重置设备", nil);
     UIButton *backbtn = [UIButton buttonWithType:UIButtonTypeCustom];
     backbtn.frame = CGRectMake(0,0,80,40);
     backbtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16.0f];
     backbtn.contentHorizontalAlignment =  UIControlContentHorizontalAlignmentLeft;
    [backbtn setImage: [UIImage imageNamed:@"button_back_lightgray_arrow"] forState:UIControlStateNormal];
    [backbtn addTarget:self action:@selector(selectLeftAction) forControlEvents:UIControlEventTouchUpInside];
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backbtn];
}

- (void)selectLeftAction
{
    [self.navigationController popViewControllerAnimated:YES];
}



- (UILabel*)titleLabel
{
    if (!_titleLabel) {
         _titleLabel = [[UILabel alloc]init];
        [self.view addSubview:_titleLabel];
         _titleLabel.textColor = [HexChangeRGB colorWithHexString:@"#333333"];
         _titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:28.0];
         _titleLabel.numberOfLines = 0;
         _titleLabel.textAlignment = NSTextAlignmentLeft;
        [_titleLabel sizeToFit];
        [_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view.mas_top).offset(30);
            make.left.equalTo(self.view.mas_left).offset(28);
        }];
   }
    return _titleLabel;
}


- (UILabel*)secondLabel
{
     if (!_secondLabel) {
         _secondLabel = [[UILabel alloc]init];
        [self.view addSubview:_secondLabel];
         _secondLabel.textColor = [HexChangeRGB colorWithHexString:@"#666666"];
         _secondLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16.0];
         _secondLabel.numberOfLines = 0;
         _secondLabel.textAlignment = NSTextAlignmentLeft;
        [_secondLabel sizeToFit];
        [_secondLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).offset(12);
            make.left.equalTo(self.view.mas_left).offset(28);
            make.right.equalTo(self.view.mas_right).offset(-28);
        }];
   }
    return _secondLabel;
}



- (UIImageView*)devicesImage
{
    if (!_devicesImage) {
         _devicesImage = [[UIImageView alloc]init];
        [self.view addSubview:_devicesImage];
        [_devicesImage mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(315);
            make.height.mas_equalTo(200);
            make.centerX.equalTo(self.view.mas_centerX);
            make.top.equalTo(self.secondLabel.mas_bottom).offset(70);
        }];
    }
    return _devicesImage;
}



-(UIButton*)selectedButton
{
     if (!_selectedButton) {
          _selectedButton =[UIButton buttonWithType:UIButtonTypeCustom];
         [_selectedButton addTarget:self action:@selector(selectedButtonclick:) forControlEvents:UIControlEventTouchUpInside];
          _selectedButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16.0];
          _selectedButton.titleLabel.textAlignment = NSTextAlignmentCenter;
         [self.view addSubview:_selectedButton];
         [_selectedButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(kScreenWidth);
            make.height.mas_equalTo(22);
            make.bottom.equalTo(self.devicesImage.mas_bottom).offset(120);
            make.centerX.equalTo(self.view.mas_centerX);
        }];
         
         [_selectedButton setImage:[UIImage imageNamed:@"cat_unselect"] forState:UIControlStateNormal];
         [_selectedButton setImage:[UIImage imageNamed:@"settingselect"] forState:UIControlStateSelected];
         [_selectedButton setTitle: NSLocalizedString(@"确认指示灯在快闪或听到提示音", nil) forState:UIControlStateNormal];
         [_selectedButton SG_imagePositionStyle:SGImagePositionStyleDefault spacing:8];
         
    }
    
    return _selectedButton;
}

- (void)selectedButtonclick:(UIButton*)sender
{
    sender.selected = !sender.selected;
    
    self.nextButton.userInteractionEnabled = sender.selected;
    if(sender.selected){
        self.nextButton.backgroundColor = [UIColor orangeColor];
       [self.nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        self.nextButton.backgroundColor = [HexChangeRGB colorWithHexString:@"#BEBBB8"];
       [self.nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
}


-(UIButton*)nextButton
{
     if (!_nextButton) {
         _nextButton = [[UIButton alloc]init];
         _nextButton.layer.cornerRadius = 25;
         _nextButton.layer.masksToBounds = YES;
         _nextButton.userInteractionEnabled = NO;
         _nextButton.backgroundColor = [HexChangeRGB colorWithHexString:@"#BEBBB8"];
        [_nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_nextButton addTarget:self action:@selector(readyBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_nextButton];
        [_nextButton mas_makeConstraints:^(MASConstraintMaker *make){
            make.width.mas_equalTo(280);
            make.height.mas_equalTo(50);
            make.top.equalTo(self.selectedButton.mas_bottom).offset(20);
            make.centerX.equalTo(self.view.mas_centerX);
        }];
    }
    return _nextButton;
}

- (void)readyBtnClick
{
    
    CatBluViewController *blu = [[CatBluViewController alloc]init];
    [self.navigationController pushViewController:blu animated:YES];
   
}

@end
